//
//  DefaultSessionContext.m
//  gongwei-ios
//
//  Created by gongwei-mac on 2020/2/4.
//  Copyright © 2020 gongwei-mac. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DefaultSessionContext.h"

@implementation DefaultSessionContext

@synthesize sessionToken = _sessionToken;
@synthesize userId = _userId;
@synthesize equipmentId = _equipmentId;

-(NSString *)getSessionToken {
    return _sessionToken;
}

-(long)getUserId {
    return _userId;
}

-(NSString *) getEquipmentId {
    return _equipmentId;
}

-(void)fillFromDictionary:(NSDictionary *)dictionary {
    NSString* sessionToken = dictionary[@"sessionToken"];
    if (sessionToken != nil)
    {
        _sessionToken = sessionToken;
    }
    
    NSNumber* userId = dictionary[@"userId"];
    if (userId != nil)
    {
        _userId = [userId longValue];
    }
    
    NSString* equipmentId = dictionary[@"equipmentId"];
    if (equipmentId != nil)
    {
        _equipmentId = equipmentId;
    }
}

-(NSMutableDictionary *)parseToDictionary: (BOOL) withTag {
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    
    if (_sessionToken != nil) {
        [dictionary setObject:_sessionToken forKey:@"sessionToken"];
    }
    
    [dictionary setObject: [NSNumber numberWithLong: _userId] forKey: @"userId"];
    
    if(_equipmentId != nil) {
        [dictionary setObject:_equipmentId forKey:@"equipmentId"];
    }
    return dictionary;
}

-(NSString *)getClassName {
    return @"com.gong_wei.common.session.DefaultSessionContext";
}

@end
